//
//  BookMarkSearchTab.swift
//  test
//
//  Created by  mahoPunch on 2021/6/11.
//

import SwiftUI

struct BookmarkSearchTab: View {
    
    @Binding var searchKeyword: String
    @Binding var isEditing:Bool

    var onEditCommit:(()->Void)?
    var onEditChanged:(()->Void)?
    
    var body: some View {
        
        HStack {
            
            Image(systemName: "magnifyingglass")
                .foregroundColor(.gray)
                .padding(.leading, 7)
            
            TextField("搜索...", text: $searchKeyword,onEditingChanged: { isEditing in
                self.isEditing = isEditing
                if isEditing {
                    onEditChanged?()
                }
            }, onCommit: {
                onEditCommit?()
            })
            .disableAutocorrection(true)
            .border(Color.white, width: 0)
            .padding(7)
            .autocapitalization(/*@START_MENU_TOKEN@*/.none/*@END_MENU_TOKEN@*/)
            
        }
        .padding(.leading, 10)
        .padding(.trailing, 10)
        .background(
            RoundedRectangle(cornerRadius: 15)
                .foregroundColor(Color(.systemGray6))
                .padding(.leading, 10)
                .padding(.trailing, 10)
        )
        
        
        
    }
}

struct BookmarkSearchTab_Previews: PreviewProvider {
    @State static var searchKeyword:String = ""
    @State static var isEditing:Bool = false;
    static var previews: some View {
        BookmarkSearchTab(searchKeyword: $searchKeyword, isEditing: $isEditing)
    }
}
